<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>预付款页面</title>
    <jsp:include page=".././../head.jsp"/>
</head>
<script type="text/javascript">
    var allFundState = ${allFundState};
    var allFundPayType = ${allFundPayType};
    var formSetting = {
        title: "预付款业务数据",
        module: 'save',
        numCount: '3',
        columns: [{
            index: "ID",
            name: "id",
            hidden: true,
            label: "id"
        }, {
            index: "BID",
            name: "bid",
            readonly: true,
            type: "dropdown",
            label: "预付款编号"
        }, {
            index: "billNo",
            name: "billNo",
            readonly: true,
            type: "dropdown",
            label: "在线支付编号"
        }, {
            index: "STATE",
            name: "state",
            readonly: true,
            type: "dropdown",
            label: "当前状态"
        }, {
            index: "FUND_PAY_TYPE",
            name: "fundPayType",
            readonly: true,
            type: "dropdown",
            label: "付款方式"
        }, {
            index: "AMOUNT",
            name: "amount",
            label: "预付款金额(元)"
        }, {
            index: "TRANSFERCERTIFICATE_ID",
            name: "transferCertificate.id",
            readonly: true,
            label: "TRANSFERCERTIFICATE_ID",
            hidden: true
        }],
        form: {
            'url': 'ajustment-saveOrUpdate',
            'data': function () {
                var id = "${id}";
                if (id) {
                    var dataValue = "";
                    $.ajax({
                               url: "ajustment-find?id=" + id,
                               async: false,
                               cache: false,
                               success: function (data) {
                                   dataValue = data;
                               }
                           });
                    return dataValue;
                } else {
                    return null;
                }
            },
            'afterAjaxSuccess': function (responseText, statusText, xhr, $form) {
                try {
                    var jr = JSON.parse(responseText.data);
                    if ("undefined" != typeof jr && "undefined" != typeof jr.purl) {
                        window.open(jr.purl);
                    }
                } catch (e) {
                }
                location.href = 'ajustment-main';
            }
        },
        buttons: {
            custom: [{
                id: "orderBtn",
                value: "马上预付款",
                click: function () {
                    var opa = $("#orderBtn").val();
                    jw.confirm("确定要" + opa + "?", function () {
                        $("input[name='state']").val("INIT");
                        $("#saveButton").click();
                    }, function () {
                        return;
                    });
                }
            }]
        }
    };
    $(document).ready(function () {
        $("#formtable").mrdForm(formSetting);
        var state = $("input[name='state']");
        var stateDropdown = $("input[name='control_fundAjustment_state_dropdown']");
        state.val(state.val() == "" ? "TEMP" : state.val());
        stateDropdown.val(stateUtil.get(allFundState, state.val()));

        $("input[name='control_fundAjustment_bid_dropdown']").val(
                $("input[name='bid']").val());
        $("input[name='control_fundAjustment_billNo_dropdown']").val(
                $("input[name='billNo']").val());

        var fundPayType = $("input[name='fundPayType']");
        var fundPayTypeDropdown = $("input[name='control_fundAjustment_fundPayType_dropdown']");
        fundPayType.val(fundPayType.val() == "" ? "ONLINE" : fundPayType.val());
        fundPayTypeDropdown.val(stateUtil.get(allFundPayType, fundPayType.val()));

        $("#saveButton").val("保存草稿");
        $("#orderBtn").css("color", "green");
        if (state.val() != "TEMP") {
            $("#saveButton").hide();
        }

        if ("" != $("input[name='billNo']").val()) {
            $("#orderBtn").val("重新支付");
            $("#orderBtn").css("color", "red");
            stateDropdown.val("支付中");
            if (state.val() == "SUCCESS") {
                $("#saveButton").hide();
                $("#orderBtn").hide();
                stateDropdown.val(stateUtil.get(allFundState, state.val()));
                $("input[name='amount']").attr("disabled", true);
            }
        }
    });
    var stateUtil = {
        get: function (arras, key) {
            for (var a in arras) {
                if (arras[a][1] == key) {
                    return arras[a][0];
                }
            }
        }
    }
    function uploadSuccessBizCallBack(id) {
        $("input[name='transferCertificate.id']").val(id)
        $("#saveButton").click();
    }
</script>
<body>
<div style="width: 100%">
    <div id="formtable"></div>
</div>
<fieldset class="replace-ui-jqgrid ui-widget ui-widget-content ui-corner-all mf_con">
    <div class="replace-ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix table_header">
        <a
                href="javascript:void(0)"
                class="replace-ui-jqgrid-titlebar-close HeaderButton tab_button"><span
                class="ui-icon ui-icon-circle-triangle-s"></span> </a><span
            class="replace-ui-jqgrid-title">预付款说明</span>
    </div>
    <p> 请填写预付款金额，金额精确到小数点后2位。</p>
    <p> 在线预付款到账需要一定时间，请耐心等候。 </p>
    <p> 重新支付将丢失当前的支付编号记录，请谨慎操作，如对预付款状态有疑问，请咨询平台客服人员。 </p>
    <p><br/></p>
</fieldset>
</body>
</html>
